#include "publicdataclass.h"

#include <QSqlQuery>


bool DB_userInfo::insertOne()
{
    QString sql = R"(INSERT INTO userInfo (
                         account,
                         name,
                         pwd,
                         isAdmin,
                         isCounselor,
                         isTeacher,
                         isStudent,
                         class_id
                     )
                     VALUES (
                         :account,
                         :name,
                         :pwd,
                         :isAdmin,
                         :isCounselor,
                         :isTeacher,
                         :isStudent,
                         :class_id);)";


//    qDebug().noquote()<<sql;

    QSqlQuery query(sql);
    query.bindValue(0,account);
    query.bindValue(1,name);
    query.bindValue(2,pwd);
    query.bindValue(3,isAdmin);
    query.bindValue(4,isCounselor);
    query.bindValue(5,isTeacher);
    query.bindValue(6,isStudent);
    query.bindValue(7,class_id);

    return exec(query);


}

bool DB_userInfo::deleteOne()
{
    QString sql = R"(DELETE FROM userInfo
      WHERE account = :account;)";

    QSqlQuery query(sql);
    query.bindValue(0,account);

    return exec(query);
}

bool DB_userInfo::updateOne()
{
    QString sql = R"(UPDATE userInfo
   SET name         = :name,
       pwd          = :pwd,
       isAdmin      = :isAdmin,
       isCounselor  = :isCounselor,
       isTeacher    = :isTeacher,
       isStudent    = :isStudent,
       class_id     = :class_id
 WHERE account      = :account;)";

//    qDebug().noquote()<<sql;

    QSqlQuery query(sql);
    query.bindValue(0,name);
    query.bindValue(1,pwd);
    query.bindValue(2,isAdmin);
    query.bindValue(3,isCounselor);
    query.bindValue(4,isTeacher);
    query.bindValue(5,isStudent);
    query.bindValue(6,class_id);
    query.bindValue(7,account);


    return exec(query);
}

bool DB_AbstractOperation::exec(QSqlQuery &query){
    return DB->exec(query);
}
